package com.ruoyi.web.controller.system;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Factor;
import com.ruoyi.system.service.FactorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description:
 * @Author:let_free
 * @Date:2024/10/2/21:58
 **/
@RestController
@Slf4j
@RequestMapping("/factor")
@Api(tags = "站点气象要素管理")
public class FactorController {
    @Autowired
    private FactorService factorService;


    @GetMapping("/latestStationFactors")
    @ApiOperation(value = "获取最近站点气象要素")
    public AjaxResult latestStationFactors() {
        return AjaxResult.success(factorService.latestStationFactors());
    }

    @GetMapping("/getList")
    @ApiOperation(value = "获取站点气象要素列表")
    public AjaxResult getList(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam Integer pageSize, @RequestParam Integer pageNum) {
        return AjaxResult.success(factorService.getList(pageNum, pageSize, startTime, endTime));
    }

    @PostMapping("/export")
    @Log(title = "当前页面站点数据", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam Integer pageSize, @RequestParam Integer pageNum) {
        List<Factor> list = factorService.getList(pageNum, pageSize, startTime, endTime).getRecords();
        ExcelUtil<Factor> util = new ExcelUtil<Factor>(Factor.class);
        util.exportExcel(response, list, "站点数据");
    }

    @PostMapping("/exportAll")
    @Log(title = "全部站点数据", businessType = BusinessType.EXPORT)
    public void exportAll(HttpServletResponse response) {
        List<Factor> list = factorService.getAllList();
        ExcelUtil<Factor> util = new ExcelUtil<Factor>(Factor.class);
        util.exportExcel(response, list, "站点数据");
    }

}
